package view.client;

import control.client.ChatAction;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

/**
 *
 * @author S3224743
 */
public class ChatFrame extends javax.swing.JFrame
{
    //private static field
    private static ChatFrame chatPanel;

    //private field
    private BaseClient baseClient;
    private String groupName;
    private ChatAction chatAction;

    //private constructor
    public ChatFrame(BaseClient baseClient)
    {
        this.initComponents();

        //Initialized
        this.baseClient=baseClient;
        this.chatAction=new ChatAction(this);

        //senderPanel
        this.senderPanel.setMinimumSize(new Dimension(0,100));
        this.senderPanel.setMaximumSize(new Dimension(0,100));
        this.senderPanel.setPreferredSize(new Dimension(0,100));

        //sendBtn
        this.sendBtn.addMouseListener(chatAction);

        //This
       this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    }

    //properties
    public BaseClient getBaseClient()
    {
        return baseClient;
    }

    public JTextArea getMessageTextArea()
    {
        return messageTextArea;
    }

    public JTextArea getSendTextArea()
    {
        return sendTextArea;
    }

    public String getGroupName()
    {
        return groupName;
    }

    public void setGroupName(String groupName)
    {
        this.groupName = groupName;
    }

    //public static method
    public static ChatFrame getInstance(BaseClient baseClient)
    {
        if(chatPanel==null)
            chatPanel=new ChatFrame(baseClient);
        return chatPanel;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        senderPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        sendTextArea = new javax.swing.JTextArea();
        sendBtn = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        messageTextArea = new javax.swing.JTextArea();

        setTitle("Chat Client");
        setMinimumSize(new java.awt.Dimension(450, 400));

        senderPanel.setMinimumSize(new java.awt.Dimension(0, 150));
        senderPanel.setPreferredSize(new java.awt.Dimension(400, 150));

        sendTextArea.setColumns(20);
        sendTextArea.setFont(new java.awt.Font("Tahoma", 0, 14));
        sendTextArea.setLineWrap(true);
        sendTextArea.setRows(4);
        jScrollPane2.setViewportView(sendTextArea);

        sendBtn.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        sendBtn.setText("Send");

        javax.swing.GroupLayout senderPanelLayout = new javax.swing.GroupLayout(senderPanel);
        senderPanel.setLayout(senderPanelLayout);
        senderPanelLayout.setHorizontalGroup(
            senderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, senderPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sendBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        senderPanelLayout.setVerticalGroup(
            senderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(senderPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(senderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sendBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                .addContainerGap())
        );

        getContentPane().add(senderPanel, java.awt.BorderLayout.PAGE_END);

        messageTextArea.setColumns(20);
        messageTextArea.setFont(new java.awt.Font("Tahoma", 0, 14));
        messageTextArea.setLineWrap(true);
        messageTextArea.setRows(5);
        jScrollPane1.setViewportView(messageTextArea);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                .addContainerGap())
        );

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea messageTextArea;
    private javax.swing.JButton sendBtn;
    private javax.swing.JTextArea sendTextArea;
    private javax.swing.JPanel senderPanel;
    // End of variables declaration//GEN-END:variables
}
